<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="format-detection" content="telephone=no">
        <title>我的</title>
        <link href="__CSS__/weui.min.css" rel="stylesheet">
       <link rel="stylesheet" href="__SaleManager__/stylesheets/distributorindex.css">

    </head>
<body>
<header class="all_header">
    <a class="h_back h_back_1 distrubutor" href="javascript:void(0)" data-role-id="{$myself.role_id}">
      <img src="__SaleManager__/images/back_icon.png" alt="">
    </a> 
    <span class="h_title">诊所分配</span> 
    <a class="h_add" href="javascript:void(0)"></a>
</header>
<!-- 分配列表 -->
<section class="distribution-list qc-wrap" id="select-more">
   <div class="dis-list-wrap" id="select-list">
     <ul>
     <volist name='clinics' id='clinic'>
     	<li data-clinic_id='{$clinic.id}'>
          <i></i>
          <h6 class="name"><strong>{$clinic.clinic_name}</strong>
          	<if condition='$clinic.type eq 1'><span style='color:red' >&nbsp;目标诊所</span>
          		<else/><span style='color:green'>&nbsp;我的诊所</span>
          	</if>
          </h6>
          <p class="sale-man">
						<volist name='lists' id='n'>
          					<if condition='$n.id eq $clinic["saleman_id"]'>
          						<switch name="n.role_id">
								    <case value="5">业务员:</case>
								    <case value="4">县总:</case>
								    <case value="3">地总:</case>
								    <default />业务员:
								</switch>
          						{$n.real_name}
          					</if>
          				</volist>
          </p>
          <p class="address">地　址：{$clinic.clinic_address}</p>
        </li>
     </volist>
     </ul>
   </div>
   <div class="dis-btn">
          <a href="#" class="w-button" id="btn_g">
            分配
          </a>        
      </div>
</section>
<!-- 分配列表 -->
<!-- 单选列表 -->
<section class="distribution-list qc-wrap" id="select-one">
   <div class="dis-list-wrap">
     <span class="close-btn iconfont">
       &#xe635;
     </span>
     <ul>
	     <volist name='lists' id='list'>
    			<li data-saleman_id='{$list.id}'>
	          <i></i>
	          <h6 class="name" >{$list.real_name}<h6>
	        </li>
	     </volist>
     </ul>
   </div>
   <div class="dis-btn">
          <a href="#" class="w-button" id="btn_one">
            确定
          </a>        
      </div>
</section>
<!-- 单选列表 -->
       <!-- 弹窗 -->    
      <div class="ui-dialog-ok" id="ok-success">
          <div class="ui-dialog-cnt">
                  <div class="header-title">
                       <h4 class="title" >分配成功</h4>
                  </div>
                  <div class="close-btn">
                      <button type="button" class="simple-close" id="dialogButton">知道了</button> 
                  </div>
          </div>        
      </div>
    <include file="./Application/Home/View/default/Saleman/Public/popup.html"/>  
    <include file="./Application/Home/View/default/SaleManager/layer/popup.html"/>
<!-- 弹窗 -->  

 <script src="__JS__/zepto.min.js"></script>
<script src = "__SaleManager__/js/Common.js"></script>
<script src = "__SaleManager__/js/androidback.js"></script>
 <script type="text/javascript">
	var sessioncode;
	var nosesstion_url;
	var returnStatus;
   $(function(){
         $("#select-more").find("li").click(function(){
             var me=$(this);
             if(me.hasClass("selected")){
                 me.removeClass("selected")
             }
             else{
                 me.addClass("selected")
             }
         })
         $("#select-one").find("li").click(function(){
             var me=$(this);
             $("#select-one").find("li").removeClass("selected");
             me.addClass("selected");
         })
         // 分配按钮
         $("#btn_g").click(function(){
        	 	clinicObj=$('#select-list').find('.selected');
      		if(clinicObj.length==0){
      			 $('#iosDialog2').find('.sure-info').html('请选择诊所');
                  $('#iosDialog2').show(200);
                  return false;
      		}
            $("#select-more").css("display","none");
            $("#select-one").css("display","block");
         })
         $("#select-one .close-btn").click(function(){
            $("#select-more").css("display","block");
            $("#select-one").css("display","none");
         })
         // 弹窗
         $("#btn_one").click(function(){
     		//1.获取所有选中诊所id
     		clinicCheck='{';
     		clinicObj=$('#select-list').find('.selected');
     		if(clinicObj.length==0){
     			 $('#iosDialog2').find('.sure-info').html('请选择诊所');
                 $('#iosDialog2').show(200);
                 return false;
     		}
     		clinicObj.each(function(key,value){
     			if(clinicObj.length-1==key){
     				 clinicCheck+='"'+key+'":'+$(value).attr("data-clinic_id")+''
     			}else{
     				 clinicCheck+='"'+key+'":'+$(value).attr("data-clinic_id")+','
     			}
           	
            });
     		clinicCheck+='}';
     		//2.获取选中业务员ID
     		salemanId=$('#select-one').find('.selected').attr('data-saleman_id');
     		if(salemanId===undefined){
     			 $('#iosDialog2').find('.sure-info').html('请选择被分配人员');
                 $('#iosDialog2').show(200);
                 return false;
     		}
     		$.ajax({
                url: "",
                type: 'POST',
                data: {'clinics':clinicCheck,'salemanId':salemanId},
                async: false,
                cache: false,
               	dataType:"json",
                success: function (returndata) {
                	//session失效
               	 	returnStatus=returndata.code;
               	 	if(returndata.code==2028){
               	 		sessioncode=2028;
               	 		nosesstion_url=returndata.data;
	        	       	 	$('.weui-dialog__bd').html(returndata.msg);
	        	     		$('#confirm_dialog').css('display','block');
               	 	}else{
	               	 	$('.weui-dialog__bd').html(returndata.msg);
	             		$('#confirm_dialog').css('display','block');
               	 	}
                },
                error: function (returndata) {
                		$('.weui-dialog__bd').html(returndata.msg);
             		$('#confirm_dialog').css('display','block');
                }
            });
			$(document).on('click','.weui-dialog__btn_primary',function(){
				if(sessioncode==2028){
					window.location.href=nosesstion_url;
				}else{
					if(returnStatus==200){
						location.href='/Home/SaleManager/County/distribution';
					}else{
						return false;
					}
					
				}
			})
            //$("#ok-success").css("display","-webkit-box")
         })
         // 关闭弹窗
         $("#ok-success .simple-close").click(function(){
            $("#ok-success").css("display","-webkit-box;")
         })
         
         $('.sure-btn').click(function(){
            $('#iosDialog2').hide(200);
            return false;
         })
   })
 </script>
</html>
